from enum import Enum
from typing import Optional

from build_feature.extract_npm_different_version_functions.core.function_info import FunctionInfo


class FunctionDifferenceType(Enum):
    ERROR = -1
    ADD = 0
    DELETE = 1
    UPDATE = 2
    HAVE = 3


class FunctionDiffInfo:

    def __init__(self, diff_type: FunctionDifferenceType,
                 from_function_info: Optional[FunctionInfo],
                 to_function_info: Optional[FunctionInfo]):
        self.diff_type = diff_type
        self.from_function_info = from_function_info
        self.to_function_info = to_function_info

    def get_diff_type(self):
        return self.diff_type

    def get_from_function_info(self):
        return self.from_function_info

    def get_to_function_info(self):
        return self.to_function_info

    @staticmethod
    def new_by_add(to_function_info: FunctionInfo):
        return FunctionDiffInfo(FunctionDifferenceType.ADD, None, to_function_info)

    @staticmethod
    def new_by_delete(from_function_info: FunctionInfo):
        return FunctionDiffInfo(FunctionDifferenceType.DELETE, from_function_info, None)

    @staticmethod
    def new_by_update(from_function_info: FunctionInfo, to_function_info: FunctionInfo):
        return FunctionDiffInfo(FunctionDifferenceType.UPDATE, from_function_info, to_function_info)
